# -*- coding:utf-8 -*-

import requests
from lxml import etree
from fake_useragent import UserAgent
from http import cookiejar
import json
from datetime import datetime
import time


requests.packages.urllib3.disable_warnings()  # 忽略HTTPS安全警告

"""
股牛牛APP-视频破解
视频地址，依据ID后数字
https://ntgapp.upchina.com/course/detail/video?id=1
以下提取网页端的视频名称
"""


class Test_Get():
    def __init__(self):
        #声明一个CookieJar对象实例来保存cookie
        self.cookie = cookiejar.CookieJar()
        ua = UserAgent(use_cache_server=False)  # 禁用服务器缓存
        self.headers = {
            # "User-Agent": ua.random
            "user-agent": "Mozilla/5.0 (Linux; Android 5.0.2; CHE-TL00H Build/HonorCHE-TL00H) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/37.0.0.0 Mobile Safari/537.36 UPHybridSDK/3.0 (teach; 2.2.0)",
        }

    def get_contents(self, current):
        url = f"https://ntgapp.upchina.com/course/detail/video?id=210"
        url = f"https://ntgapp.upchina.com/course/detail/video?id={current}"
        time.sleep(1)
        # html = requests.get(url, headers=self.headers)
        html = HttpUtils.do_request("GET", url, self.headers, "")
        root = etree.HTML(html.text)
        title = root.xpath('//p[@class="video_title share_title"]/text()')[0]
        username = "".join(root.xpath('//div[@class="video_master"]/p/span//text()'))
        print("==================")
        print(title)
        print(username)
        print(url)


if __name__ == '__main__':
    test_get = Test_Get()
    for i in range(1, 243):
        print(i)
        test_get.get_contents(i)